<?php
// +----------------------------------------------------------------------
// | 后台用户管理
// +----------------------------------------------------------------------
namespace app\admin\controller\soft;
use app\app\Appbase;
use base\files\Poster;

class Spread extends Appbase 
{
	
	/**
	* 生成海报
	* /admin/soft/spread/imgs
	* 需要登录 
	* @is_need_login false
	*/
	public function imgs($sid=1,$bg='',$size=0,$x=0,$y=0){
		$uid = request() ->userId;
		try {
			$url = getSystem("extension_poster_url") .'?sid='. ($sid ?: $uid);
			$bg = $bg ?: getSystem("extension_poster_tpl_bg");
			$size = $size ?: getSystem("extension_poster_tpl_size");
			$size = $size < 50 ? 50 : $size;
			$x = $x ?: getSystem("extension_poster_tpl_x");
			$y = $y ?: getSystem("extension_poster_tpl_y");
			Poster::generate($bg,$url,$size,$x,$y);
		} catch (\Exception $e) {
			return $this->ReError($e->getMessage());	
		}
	}
	
	
	/**
	* 参数活动推广海报设置
	* /admin/soft/Spread/posterSet
	* 需要登录 
	* @is_need_login true
	*/
	public function posterSet(){
		$bg = request()->param('extension_poster_tpl_bg',''); 
		$size = request()->param('extension_poster_tpl_size',150); 
		$x = request()->param('extension_poster_tpl_x',50); 
		$y = request()->param('extension_poster_tpl_y',50); 
		
		try {
			model('SystemParamValue')->where('param_code','like','%extension_poster_tpl%')->delete();
		
			$list = [
			    ['param_scope'=>'业务参数', 'param_code'=>'extension_poster_tpl_size','param_value'=>$size],
			    ['param_scope'=>'业务参数', 'param_code'=>'extension_poster_tpl_bg','param_value'=>$bg],
			    ['param_scope'=>'业务参数', 'param_code'=>'extension_poster_tpl_x','param_value'=>$x],
			    ['param_scope'=>'业务参数', 'param_code'=>'extension_poster_tpl_y','param_value'=>$y]
			];
			$result = model('SystemParamValue')->saveAll($list);
			
			if(!$result){
				return $this->ReError($result);
			}
			return $this->ReSucess(true);	
			
		} catch (\Exception $e) {
			return $this->ReError($e->getMessage());	
		}
	}
}

